//
//  BieRenDongTaiViewController.m
//  qiJi
//
//  Created by 凤利史 on 2018/4/19.
//  Copyright © 2018年 sunrose. All rights reserved.
//

#import "BieRenDongTaiViewController.h"
#import "BieRenDongTaiOneTableViewCell.h"
#import "BieRenDongTaiSectionView.h"
#import "BieRenDongTaiTwoTableViewCell.h"

@interface BieRenDongTaiViewController ()<UITableViewDelegate , UITableViewDataSource>
@property(nonatomic,strong) UITableView *tableView;

@end

@implementation BieRenDongTaiViewController
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = getColor(@"FAFAFA");
    [self creationView];
    [self regeditCell];
    
    // Do any additional setup after loading the view.
}
- (void)creationView{
    
    
    
    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT);
    
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    
    
}
- (void)regeditCell{
    
    //
    [self.tableView registerNib:[UINib nibWithNibName:@"BieRenDongTaiOneTableViewCell" bundle:nil] forCellReuseIdentifier:@"BieRenDongTaiOneTableViewCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"BieRenDongTaiTwoTableViewCell" bundle:nil] forCellReuseIdentifier:@"BieRenDongTaiTwoTableViewCell"];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BieRenDongTaiSectionView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"BieRenDongTaiSectionView"];
    
};
#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
#pragma mark - ---------- Section的内容 ----------
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 1) {
        BieRenDongTaiSectionView *sectionView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:@"BieRenDongTaiSectionView"];
        
        return sectionView;
    }else{
        
        return nil;
    }
    
    
    
    
    
    
}
#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    }else{
        return 40;
    }
}

#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
        return 10;
    }
    
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        return 280;
    }else {
        return 360;
    }
    
}

//section 不随tableView滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.tableView)
        
    {
        
        CGFloat sectionHeaderHeight = 64; //header高度
        
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
        
    }
    
    
    
}

#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section == 0) {
        BieRenDongTaiOneTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"BieRenDongTaiOneTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell.backButton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
        
        return cell;
    }else{
        
        BieRenDongTaiTwoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"BieRenDongTaiTwoTableViewCell" forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        return cell;
        
    }
    
    
    
    
}

#pragma mark - ---------- 每个Cell的点击事件 ----------
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    
    
}

- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
